home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / ip.h < prev    next >
C/C++ Source or Header  |  1992-05-28  |  8KB  |  228 lines

  1. /* @(#) $Header: ip.h,v 1.9 92/05/28 13:50:17 deyke Exp $ */
  2.  
  3. #ifndef _IP_H
  4. #define _IP_H
  5.  
  6. #ifndef _GLOBAL_H
  7. #include "global.h"
  8. #endif
  9.  
  10. #ifndef _MBUF_H
  11. #include "mbuf.h"
  12. #endif
  13.  
  14. #ifndef _IFACE_H
  15. #include "iface.h"
  16. #endif
  17.  
  18. #ifndef _INTERNET_H
  19. #include "internet.h"
  20. #endif
  21.  
  22. #ifndef _TIMER_H
  23. #include "timer.h"
  24. #endif
  25.  
  26. #define TLB             30      /* Default reassembly timeout, sec */
  27. #define IPVERSION       4
  28. #define IP_CS_OLD       1       /* use saved checksum */
  29. #define IP_CS_NEW       0       /* calculate checksum */
  30.  
  31. extern char Hashtab[];  /* Modulus lookup table */
  32.  
  33. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  34. extern struct mib_entry Ip_mib[];
  35. #define ipForwarding            Ip_mib[1].value.integer
  36. #define ipDefaultTTL            Ip_mib[2].value.integer
  37. #define ipInReceives            Ip_mib[3].value.integer
  38. #define ipInHdrErrors           Ip_mib[4].value.integer
  39. #define ipInAddrErrors          Ip_mib[5].value.integer
  40. #define ipForwDatagrams         Ip_mib[6].value.integer
  41. #define ipInUnknownProtos       Ip_mib[7].value.integer
  42. #define ipInDiscards            Ip_mib[8].value.integer
  43. #define ipInDelivers            Ip_mib[9].value.integer
  44. #define ipOutRequests           Ip_mib[10].value.integer
  45. #define ipOutDiscards           Ip_mib[11].value.integer
  46. #define ipOutNoRoutes           Ip_mib[12].value.integer
  47. #define ipReasmTimeout          Ip_mib[13].value.integer
  48. #define ipReasmReqds            Ip_mib[14].value.integer
  49. #define ipReasmOKs              Ip_mib[15].value.integer
  50. #define ipReasmFails            Ip_mib[16].value.integer
  51. #define ipFragOKs               Ip_mib[17].value.integer
  52. #define ipFragFails             Ip_mib[18].value.integer
  53. #define ipFragCreates           Ip_mib[19].value.integer
  54.  
  55. #define NUMIPMIB        19
  56.  
  57. /* IP header, INTERNAL representation */
  58. #define IPLEN           20      /* Length of standard IP header */
  59. #define IP_MAXOPT       40      /* Largest option field, bytes */
  60. struct ip {
  61.     int32 source;           /* Source address */
  62.     int32 dest;             /* Destination address */
  63.     int16 length;           /* Total length */
  64.     int16 id;               /* Identification */
  65.     int16 offset;           /* Fragment offset in bytes */
  66.     int16 checksum;         /* Header checksum */
  67.  
  68.     struct {
  69.         char congest;   /* Congestion experienced bit (exp) */
  70.         char df;        /* Don't fragment flag */
  71.         char mf;        /* More Fragments flag */
  72.     } flags;
  73.  
  74.     char version;           /* IP version number */
  75.     char tos;               /* Type of service */
  76.     char ttl;               /* Time to live */
  77.     char protocol;          /* Protocol */
  78.     char optlen;            /* Length of options field, bytes */
  79.     char options[IP_MAXOPT];/* Options field */
  80. };
  81. #define NULLIP  (struct ip *)0
  82.  
  83. /* Fields in option type byte */
  84. #define OPT_COPIED      0x80    /* Copied-on-fragmentation flag */
  85. #define OPT_CLASS       0x60    /* Option class */
  86. #define OPT_NUMBER      0x1f    /* Option number */
  87.  
  88. /* IP option numbers */
  89. #define IP_EOL          0       /* End of options list */
  90. #define IP_NOOP         1       /* No Operation */
  91. #define IP_SECURITY     2       /* Security parameters */
  92. #define IP_LSROUTE      3       /* Loose Source Routing */
  93. #define IP_TIMESTAMP    4       /* Internet Timestamp */
  94. #define IP_RROUTE       7       /* Record Route */
  95. #define IP_STREAMID     8       /* Stream ID */
  96. #define IP_SSROUTE      9       /* Strict Source Routing */
  97.  
  98. /* Timestamp option flags */
  99. #define TS_ONLY         0       /* Time stamps only */
  100. #define TS_ADDRESS      1       /* Addresses + Time stamps */
  101. #define TS_PRESPEC      3       /* Prespecified addresses only */
  102.  
  103. /* IP routing table entry */
  104. struct route {
  105.     struct route *prev;     /* Linked list pointers */
  106.     struct route *next;
  107.     int32 target;           /* Target IP address */
  108.     unsigned int bits;      /* Number of significant bits in target */
  109.     int32 gateway;          /* IP address of local gateway for this target */
  110.     int32 metric;           /* Hop count or whatever */
  111.     struct iface *iface;    /* Device interface structure */
  112.     int flags;
  113. #define RTPRIVATE       0x1     /* Should the world be told of this route ? */
  114. #define RTTRIG  0x2             /* Trigger is pending for this route */
  115.     struct timer timer;     /* Time until aging of this entry */
  116.     int32 uses;             /* Usage count */
  117. };
  118. #define NULLROUTE       (struct route *)0
  119. extern struct route *Routes[32][HASHMOD];       /* Routing table */
  120. extern struct route R_default;                  /* Default route entry */
  121.  
  122. /* Cache for the last-used routing entry, speeds up the common case where
  123.  * we handle a burst of packets to the same destination
  124.  */
  125. struct rt_cache {
  126.     int32 target;
  127.     struct route *route;
  128. };
  129.  
  130. /* Reassembly descriptor */
  131. struct reasm {
  132.     struct reasm *next;     /* Linked list pointer */
  133.     struct timer timer;     /* Reassembly timeout timer */
  134.     struct frag *fraglist;  /* Head of data fragment chain */
  135.     int16 length;           /* Entire datagram length, if known */
  136.     int32 source;           /* src/dest/id/protocol uniquely describe a datagram */
  137.     int32 dest;
  138.     int16 id;
  139.     char protocol;
  140. };
  141. #define NULLREASM       (struct reasm *)0
  142.  
  143. /* Fragment descriptor in a reassembly list */
  144. struct frag {
  145.     struct frag *prev;      /* Previous fragment on list */
  146.     struct frag *next;      /* Next fragment */
  147.     struct mbuf *buf;       /* Actual fragment data */
  148.     int16 offset;           /* Starting offset of fragment */
  149.     int16 last;             /* Ending offset of fragment */
  150. };
  151. #define NULLFRAG        (struct frag *)0
  152.  
  153. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  154.  
  155. /* Structure for handling raw IP user sockets */
  156. struct raw_ip {
  157.     struct raw_ip *next;    /* Linked list pointer */
  158.  
  159.     struct mbuf *rcvq;      /* receive queue */
  160.     void (*r_upcall) __ARGS((struct raw_ip *));
  161.     int protocol;           /* Protocol */
  162.     int user;               /* User linkage */
  163. };
  164. #define NULLRIP ((struct raw_ip *)0)
  165.  
  166. /* Transport protocol link table */
  167. struct iplink {
  168.     char proto;
  169.     void (*funct) __ARGS((struct iface *,struct ip *,struct mbuf *,int));
  170. };
  171. extern struct iplink Iplink[];
  172.  
  173. /* List of TCP port numbers to be given priority queuing */
  174. extern int Tcp_interact[];
  175.  
  176. /* In ip.c: */
  177. void ip_garbage __ARGS((int drastic));
  178. void ip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  179.     int rxbroadcast));
  180. void ipip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  181.     int rxbroadcast));
  182. int ip_send __ARGS((int32 source,int32 dest,int protocol,int tos,int ttl,
  183.     struct mbuf *bp,int length,int id,int df));
  184. struct raw_ip *raw_ip __ARGS((int protocol,void (*r_upcall) __ARGS((struct raw_ip *)) ));
  185. void del_ip __ARGS((struct raw_ip *rrp));
  186.  
  187. /* In iproute.c: */
  188. void ipinit __ARGS((void));
  189. int16 ip_mtu __ARGS((int32 addr));
  190. void encap_tx __ARGS((int dev,void *arg1,void *unused));
  191. int ip_encap __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,
  192.     int prec,int del,int tput,int rel));
  193. void ip_proc __ARGS((struct iface *iface,struct mbuf *bp));
  194. int ip_route __ARGS((struct iface *i_iface,struct mbuf *bp,int rxbroadcast));
  195. int32 locaddr __ARGS((int32 addr));
  196. void rt_merge __ARGS((int trace));
  197. struct route *rt_add __ARGS((int32 target,unsigned int bits,int32 gateway,
  198.     struct iface *iface,int32 metric,int32 ttl,int private));
  199. int rt_drop __ARGS((int32 target,unsigned int bits));
  200. struct route *rt_lookup __ARGS((int32 target));
  201. struct route *rt_blookup __ARGS((int32 target,unsigned int bits));
  202.  
  203. /* In iphdr.c: */
  204. int16 cksum __ARGS((struct pseudo_header *ph,struct mbuf *m,int len));
  205. int16 eac __ARGS((int32 sum));
  206. struct mbuf *htonip __ARGS((struct ip *ip,struct mbuf *data,int cflag));
  207. int ntohip __ARGS((struct ip *ip,struct mbuf **bpp));
  208.  
  209. /* In either lcsum.c or pcgen.asm: */
  210. int16 lcsum __ARGS((int16 *wp,int len));
  211.  
  212. /* In ipsocket.c: */
  213. int so_ip_sock __ARGS((struct usock *up,int protocol));
  214. int so_ip_conn __ARGS((struct usock *up));
  215. int so_ip_recv __ARGS((struct usock *up,struct mbuf **bpp,char *from,
  216.     int *fromlen));
  217. int so_ip_send __ARGS((struct usock *up,struct mbuf *bp,char *to));
  218. int so_ip_qlen __ARGS((struct usock *up,int rtx));
  219. int so_ip_close __ARGS((struct usock *up));
  220. int checkipaddr __ARGS((char *name,int namelen));
  221. char *ippsocket __ARGS((struct sockaddr *p));
  222.  
  223. /* In ipfile.c: */
  224. void route_savefile __ARGS((void));
  225. void route_loadfile __ARGS((void));
  226.  
  227. #endif /* _IP_H */
  228.